import echarts from 'echarts';
// 引入柱状图
import 'echarts/lib/chart/bar';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
import storageApi from '../../../core/storage/storage';

function supervisorTopController($rootScope, $scope, homeStatsService, toDoService) {
  'ngInject';

  /*eslint-disable */
  this.queryTenderProgres = () => {
    this.hasProjectInfo = false;
    homeStatsService.queryTenderProgres({ mapParams: {orgId: $rootScope.orgId || storageApi.get('orgId') } }).then((res) => {
      if (res.success && res.rows.length > 0) {
        this.projectInfo = res.rows[0];
        this.hasProjectInfo = true;
      }
    });
  };

  // 人员
  this.queryStaffInOutStatistics = () => {
    homeStatsService
      .queryJLStaffInOutStatistics({ orgId: $rootScope.orgId || storageApi.get('orgId') })
      .then((res) => {
        if (res.success) {
          if (res.rows && res.rows.length > 0) {
            this.staffInOut = res.rows[res.rows.length - 1];
          }
        }
      });
  };

  this.initChart = () => {
    const option = {
      color: ['#8fd7ee'],
      tooltip : {
        trigger: 'axis'
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis : [
        {
          type : 'category',
          boundaryGap : false,
          data : ['3.1','3.2','3.3','3.4','3.5','3.6','3.7']
        }
      ],
      yAxis : [
        {
          type : 'value'
        }
      ],
      series : [
        {
          name:'安全指数',
          type:'line',
          stack: '总量',
          areaStyle: {
            normal: {},
          },
          data:[20, 50, 80, 90, 130, 180, 200]
        }
      ]
    };
    const myChart = echarts.init(document.getElementById('supervisor-top-month-safety'));
    myChart.setOption(option);
  }

  // 代办
  this.queryTodo = () => {
    this.mapParams = {
      orgId: $rootScope.orgId || storageApi.get('orgId'),
      todoType: 0,
    };
    toDoService
      .query({
        mapParams: this.mapParams,
        page: 1,
        size: 10,
      })
      .then((res) => {
        this.todoTotal = res.total;
      });
  };

  this.initChart();
  this.queryTenderProgres();
  this.queryStaffInOutStatistics();
  this.queryTodo();
}

export default supervisorTopController;
